package com.owen.java.demo.io.bio;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.nio.charset.Charset;

public class SocketClient {

    public static void main(String[] args) {
        try (
                Socket socket = new Socket("localhost", 8888);
                OutputStream outputStream = socket.getOutputStream();
                InputStream inputStream=socket.getInputStream();) {
            while (true){
                outputStream.write("afdsafewf".getBytes(Charset.defaultCharset()));
                outputStream.flush();

                byte[] data=new byte[1024];
                inputStream.read(data);
                System.out.println(new String(data,Charset.defaultCharset()));
            }
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
